package com.example.its2021606134chh.MyCarModule;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.its2021606134chh.ETCModule.Cars;
import com.example.its2021606134chh.R;

import java.util.List;

public class MyCarRViewAdapter extends RecyclerView.Adapter<MyCarRViewAdapter.ViewHolder> {
    private List<Cars> list;
    public MyCarRViewAdapter(List<Cars> list) {
        this.list = list;
    }
    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvItemId, tvItemCarId, tvItemRechargeNum, tvItemRechargeDate;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvItemId = itemView.findViewById(R.id.tvItemId);
            tvItemCarId = itemView.findViewById(R.id.tvItemCarId);
            tvItemRechargeNum = itemView.findViewById(R.id.tvItemRechargeNum);
            tvItemRechargeDate = itemView.findViewById(R.id.tvItemRechargeDate);
        }
    }
    @NonNull
    @Override
    public MyCarRViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_mc_recharge, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyCarRViewAdapter.ViewHolder holder, int position) {
        Cars Cars = list.get(position);
        holder.tvItemId.setText(String.valueOf(position + 1));
        holder.tvItemCarId.setText(String.valueOf(Cars.getCarID()));
        holder.tvItemRechargeNum.setText(String.valueOf(Cars.getCarRecharge()));
        holder.tvItemRechargeDate.setText(String.valueOf(Cars.getTime()));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
}
